package ch06.d2;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class DateTest {
    @Test
    public void test1() throws ParseException, InterruptedException {
        while(true){
            m3();
            Thread.sleep(1000);//休眠1秒
        }

    }

    public void m3() throws ParseException {
        Date newYear=new SimpleDateFormat("yyyy-MM-dd").parse("2024-02-10");
        Date now=new Date();

        long diff=newYear.getTime()-now.getTime();//毫秒
        diff/=1000;//秒

        //天
        long d=diff/24/3600;
        diff%=24*3600;

        //小时
        long h=diff/3600;
        diff%=3600;

        //分钟
        long m=diff/60;
        diff%=60;

        //秒
        long s=diff;

        System.out.println(d+"天"+h+"小时"+m+"分钟"+s+"秒");


    }
    public String m2(long seconds){
        SimpleDateFormat sdf;
        if(seconds<3600){
            sdf=new SimpleDateFormat("mm:ss");
        }else{
            sdf=new SimpleDateFormat("yyyy年MM月dd天HH:mm:ss");
        }

        sdf.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
        Date d=new Date(seconds*1000l);

        String s=sdf.format(d);
        return s;
    }
    public String m1(int seconds){
        //数字计算
        // 70s = 1m 10s
        //小时
        int h=seconds/3600;
        seconds=seconds%3600;

        //分钟
        int m=seconds/60;

        //秒
        int s=seconds%60;
        if(h==0){
            return m+":"+s;
        }

        return h+":"+m+":"+s;
    }

    @Test
    public void testCar(){
        Car c=new Car(3,3,"E");
        c.move("MMRMMRMRRM");
        System.out.println(c);

    }
}
